package com.lzh.chatnote.common.domian.vo.response;

import cn.hutool.core.collection.CollectionUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collections;
import java.util.List;


@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel("游标分页响应参数")
@Data
public class CursorPageBaseResp <T>{

    @ApiModelProperty("游标参数")
    private String cursor;

    @ApiModelProperty("是否最后一页")
    private Boolean isLast;

    @ApiModelProperty("数据列表")
    private List<T> list;



    /**
     * 构建响应vo
     * @param resp resp vo对象
     * @param data  数据列表
     * @return 响应vo对象
     */
    public static  <E>  CursorPageBaseResp<E>  buildVO(CursorPageBaseResp resp, List<E> data){
        return  CursorPageBaseResp
                .<E>builder()
                .list(data)
                .isLast(resp.getIsLast())
                .cursor(resp.getCursor())
                .build();
    }

    /**
     * 构建空数据vo
     * @return 响应vo对象
     */
    public static <E> CursorPageBaseResp<E> buildEmpty(){
        return  CursorPageBaseResp
                .<E>builder()
                .list(Collections.emptyList())
                .isLast(true)
                .build();
    }

    @JsonIgnore
    public Boolean isEmpty() {
        return CollectionUtil.isEmpty(list);
    }




}
